﻿/* 
 * Shuriken is the legal property of its developers. Please refer to the
 * COPYRIGHT file distributed with this
 * source distribution.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Shuriken.Base
{
    public class GeneralAction : IAction
    {
        private string m_ActionName;
        private string m_ActionDescription;
        private string m_ActionIcon;
        private ActionExecuteDelegate m_ExecuteAction;
        private System.Type m_SubjectType;
        private bool m_DefaultAction;
        private string m_ActionAttribute;
        private bool m_IsActionAttributed;

        public GeneralAction(string Name, string Description, string Icon, bool defaultaction, bool actionattributed, ActionExecuteDelegate executeActionDelegate, System.Type subjecttype)
        {
            m_ActionName = Name;
            m_ActionDescription = Description;
            m_ActionIcon = Icon;

            System.Diagnostics.Trace.Assert(executeActionDelegate != null, "executor received for action " + Name + " is null!");
            m_ExecuteAction = executeActionDelegate;

            m_SubjectType = subjecttype;
            m_DefaultAction = defaultaction;
            m_IsActionAttributed = actionattributed;
        }

        #region IAction Members

        public void Execute(ISubject subject)
        {
            if (m_ExecuteAction != null)
            {
                m_ExecuteAction.Invoke(subject);
            }
        }

        public bool CanExecuteOn(ISubject subject)
        {
            return true;
        }

        public Type SubjectType
        {
            get { return m_SubjectType; }
        }

        public bool IsDefault
        {
            get { return m_DefaultAction; }
        }

        public string ActionAttribute
        {
            get
            {
                return m_ActionAttribute;
            }
            set
            {
                m_ActionAttribute = value;
            }
        }

        public bool IsAttributed
        {
            get { return m_IsActionAttributed; }
        }

        #endregion

        #region IObject Members

        public string Name
        {
            get { return m_ActionName; }
        }

        public string Description
        {
            get { return m_ActionDescription; }
        }

        public string Icon
        {
            get
            {
                return m_ActionIcon;
            }
            set
            {
                m_ActionIcon = value;
            }
        }

        #endregion
    }

    public delegate void ActionExecuteDelegate(ISubject subject); 
}
